//
//  EWEApi.swift
//  EWEMDT3
//
//  Created by 来 on 2019/11/19.
//  Copyright © 2019 laiguofeng. All rights reserved.
//

import Foundation

class EWEApi {
    
    var root: [String: Any] = [
        // 登录
        // hidoctor.access.auth
        "hidoctor.access.auth": [
            "type": "POST",
            "method": "hidoctor.access.auth"
        ],
        // 签名
        "hidoctor.mobile.ca.addSignJob": [
            "type": "GET",
            "method": "hidoctor.mobile.ca.addSignJob"
        ],
        "format": "json",
        "v": "1.3",
        "SystemAES": true
    ]
    
    /// 单例
    public static let lgf = EWEApi()
    private init(){
        format = (root["format"] as? String) ?? ""
        if format != "json" {
            SVProgressHUD.showError("配置文件 format 值出现问题")
            return
        }
        v = (root["v"] as? String) ?? ""
        if v.count == 0 {
            SVProgressHUD.showError("配置文件 v 未设置")
            return
        }
        SA = (root["SystemAES"] as? Bool) ?? false
    }
    
    public var format: String!
    public var v: String!
    public var SA: Bool!
    
    public func type(_ method: String) -> String {
        let dict = root[method] as? [String: String]
        let dictMethod = dict?["method"] ?? ""
        let dictType = dict?["type"] ?? ""
        if !root.keys.contains(method) {
            SVProgressHUD.showError("配置文件里面的 method 不匹配")
        }
        if dictMethod != method {
            SVProgressHUD.showError("配置文件里面的 method 匹配错误")
        }
        return dictType
    }
    
    public func method(_ method: String) -> String {
        let dict = root[method] as? [String: String]
        let dictMethod = dict?["method"] ?? ""
        let dictType = dict?["type"] ?? ""
        if !root.keys.contains(method) {
            SVProgressHUD.showError("配置文件里面的 method 不匹配")
        }
        if dictMethod != method {
            SVProgressHUD.showError("配置文件里面的 method 匹配错误")
        }
        return dictType
    }
    
}
